package com.sky.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sky.dto.NonheritageImgDTO;
import com.sky.entity.Inheritors;
import com.sky.entity.NonheritageImg;
import com.sky.result.Result;
import com.sky.service.NonheritageImgService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/nonHeritageImg")
@Api(tags = "管理端非遗图相关接口")
@Slf4j
public class NonheritageImgController {
    @Autowired
    private NonheritageImgService nonHeritageImgService;

    /**
     * 新增非遗图
     */
    @PostMapping
    public Result<String> post(@RequestBody NonheritageImgDTO img) {
        NonheritageImg nonHeritageImg = new NonheritageImg();
        BeanUtils.copyProperties(img, nonHeritageImg);
        nonHeritageImgService.save(nonHeritageImg);
        return Result.success();
    }

    /**
     * 删除非遗图
     */
    @DeleteMapping
    public Result<String> delete(@RequestParam List<String> ids) {
        nonHeritageImgService.removeByIds(ids);
        return Result.success();
    }

    /**
     * 根据非遗id查询非遗图
     */
    @GetMapping("/{id}")
    public Result<List<NonheritageImg>> get(@PathVariable Integer id) {
        List<NonheritageImg> nonheritageImgs= nonHeritageImgService.getByNonheritage(id);
        log.info("{}",nonheritageImgs);
        return Result.success(nonHeritageImgService.getByNonheritage(id));
    }
}
